﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SportsStore.WebUI
{
    public class RouteConfig
    {
        public static void RegisterRoutes( RouteCollection routes )
        {
            routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );

            // / - List the first page of products from all categories
            routes.MapRoute
            (
                name: null,
                url: "",
                defaults: new
                {
                    Controller = "Product",
                    Action = "List",
                    Category = (string) null,
                    Page = 1
                }
            );

            // /Page2 - List the specified page (in this case, page 2),
            //          showing items from all categories
            routes.MapRoute
            (
                name: null,
                url: "Page{page}",
                defaults: new 
                { 
                    Controller = "Product", 
                    Action = "List",
                    Category = (string) null
                },
                constraints: new { Page = @"\d+" }
            );

            // /Soccer - Shows the first page of items from a specific 
            //           category (in this case, the Soccer category).
            routes.MapRoute
            (
                name: null,
                url: "{category}",
                defaults: new
                {
                    Controller = "Product",
                    Action = "List",
                    Page = 1
                }
            );

            // /Soccer/Page2 - Shows the specified page (in this case,
            //                 page 2) of items from the specified
            //                 category (in this case, Soccer)
            routes.MapRoute
            (
                name: null,
                url: "{category}/Page{page}",
                defaults: new
                {
                    Controller = "Product",
                    Action = "List",
                },
                constraints: new { Page = @"\d+" }
            );

            // /Anything/Else - Calls the Else action method on the
            //                  Anything controller
            routes.MapRoute
            (
                name: null,
                url: "{controller}/{action}"
            );
        }
    }
}